package com.sense.kukoo.biz_media.model

import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.CommentRecordBean
import okhttp3.RequestBody

class MediaCommentModel: BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName

    override fun onModelCleared() {}

    suspend fun commentList(
        contentId: Long,
        parentId: Long,
        pageIndex: Int,
        pageSize: Int,
    ): ResultBean<ArrayList<CommentRecordBean>> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("contentId", contentId)
        if(false){
            hashMap.put("limit1", "limit1")
            hashMap.put("limit2", "limit2")
        }
        hashMap.put("pageIndex", pageIndex)
        hashMap.put("pageSize", pageSize)
        hashMap.put("parentId", parentId)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .commentList(mRequestBody)
    }

    suspend fun commentSave(
        contentId: Long,
        contentUserId: Long,
        content: String,
        replyUserName: String,
        parentId: Long,
        replyUserId: Long,
    ): ResultBean<CommentRecordBean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("contentId", contentId)
        hashMap.put("content", content)
        hashMap.put("contentUserId", contentUserId)
        hashMap.put("parentId", parentId)
        hashMap.put("replyUserId", replyUserId)
        hashMap.put("replyUserName", replyUserName)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .commentSave(mRequestBody)
    }

    suspend fun commentRemove(
        id: Long,
    ): ResultBean<Boolean> {

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .commentRemove("${id}")
    }
}